package com.lt.lumentracks.config;


import com.lt.lumentracks.interceptor.LoginCheckInterceptor_client;
import com.lt.lumentracks.interceptor.RequestLoggingInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration //配置类
public class InterceptorConfig implements WebMvcConfigurer {


    @Autowired
    private LoginCheckInterceptor_client loginCI_C;
    @Autowired
    private RequestLoggingInterceptor requestLI;

    @Override //注册拦截器
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(loginCI_C).addPathPatterns("/**")
                .excludePathPatterns(
                        "/post/get*/**", "/post/feed*/**",
                        "/tag/**",
                        "/topic/**",
                        "/comment/get/**",
                        "/user/getById*/**", "/user/login/**", "/user/register/**", "/user/getUserInfoByJwt/**",
                        "/common/jwt/**"
                )
                .excludePathPatterns("/error"); // 避免拦截器处理/error请求，应直接返回原始错误信息

        registry.addInterceptor(requestLI).addPathPatterns("/**");

    }
}
